//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by 贵永冬 on 16/7/16.
//  Copyright © 2016年 贵永冬. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    /**
     创建navigationBar 登陆注册 uitabbarItem
     */
    convenience init(target: AnyObject ,action: Selector, title: String, isLeft:Bool, titleColor:UIColor) {
        let loginButton = UIButton(type: UIButtonType.Custom)
        loginButton.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        loginButton.setTitle(title, forState: UIControlState.Normal)
        loginButton.setTitleColor(titleColor, forState: UIControlState.Normal)
        loginButton.titleLabel?.font = UIFont.systemFontOfSize(15)
        loginButton.frame = CGRect(x: 0, y: 4, width: 50, height: 40)
        if isLeft {
            loginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
        }else {
            loginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right
        }
        
        self.init(customView:loginButton)
    }
    convenience init(target: AnyObject ,action: Selector, imageName: String, isLeft:Bool) {
        let button = UIButton(type: UIButtonType.Custom)
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.frame = CGRect(x: 0, y: 4, width: 50, height: 40)
        if isLeft {
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
        }else {
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right
        }
        
        self.init(customView:button)
    }
    
}
